package com.ruoyi.sms;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.springframework.stereotype.Service;

@Service
public class SmsSender {
	
	 
	/**
	 * 发短信内容模板【智慧旅游】您正在****验证，验证码******，请在15分钟内按页面提示提交验证码，切勿将验证码泄露与他人。
	 * @param mobile 手机号码
	 * @param code  验证码
	 * @param buzStr 业务内容（登录、注册等）
	 */
	public void sendSms(String mobile,String code,String buzStr) {
		 String host = "https://dxyzm.market.alicloudapi.com";
		 String path = "/chuangxin/dxjk";
		 String method = "POST";
		 String appcode = "07cc52ec1047427abce10f29d244086f";
		 Map<String, String> headers = new HashMap<String, String>();
		    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
		    headers.put("Authorization", "APPCODE " + appcode);
		    Map<String, String> querys = new HashMap<String, String>();
		    querys.put("content", "您的验证码为："+code+"，请在15分钟内按页面提示提交验证码，请勿告诉他人，以免造成损失。");
		    querys.put("mobile", mobile);
		    Map<String, String> bodys = new HashMap<String, String>();
		    
            try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = SmsHttpUtils.doPost(host, path, method, headers, querys, bodys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	//System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}
	
	/**
	 * 发短信内容模板【智慧旅游】您正在****验证，验证码******，请在15分钟内按页面提示提交验证码，切勿将验证码泄露与他人。
	 * @param mobile 手机号码
	 * @param code  验证码
	 * @param buzStr 业务内容（登录、注册等）
	 */
	public void sendSms(String mobile,String code) {
		 String host = "https://dxyzm.market.alicloudapi.com";
		 String path = "/chuangxin/dxjk";
		 String method = "POST";
		 String appcode = "07cc52ec1047427abce10f29d244086f";
		 Map<String, String> headers = new HashMap<String, String>();
		    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
		    headers.put("Authorization", "APPCODE " + appcode);
		    Map<String, String> querys = new HashMap<String, String>();
		    querys.put("content", "【智慧旅游】您正在操作验证，验证码"+code+"，请在15分钟内按页面提示提交验证码，切勿将验证码泄露与他人。");
		    querys.put("mobile", mobile);
		    Map<String, String> bodys = new HashMap<String, String>();
		    
            try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = SmsHttpUtils.doPost(host, path, method, headers, querys, bodys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	//System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}

	public static void main(String[] args) {
	    
		SmsSender sms=new SmsSender();
		sms.sendSms("15078917719", "12344","登录");

	   
	}

}
